var IndexTool =function(){
	return {
		//动态设置图表外框的高度
		setWidth : function(){
			var mainWidth = $('#main').width(),
			mainHeight = mainWidth*0.7;
			$('.e-wrap').height(mainHeight);
		},
		getData : function(){
			//显示数据
			$.ajax({
				url: ctx +'/view/get.mvc',
			    type:"post", 
			    dataType:'json',
			    data : {},
			    success: function(data){
					console.info(data);
			    	if(data.result ==true){
			    		//文字显示
			    		$(".page-container .num").html(data.data.num);
			    		$(".page-container .runTime").html(data.data.runTime);
			    		$(".page-container .stopTime").html(data.data.stopTime);
			    		$(".page-container .electricity").html(data.data.electricity);
			    		$(".page-container .water").html(data.data.water);
			    		
			    		//三个图标显示
			    		//------------------------------图表配置------------------------------------>>
			    	    var myChart = echarts.init(document.getElementById('main'),'macarons');
			    	    var myChart2 = echarts.init(document.getElementById('main2'),'macarons');
			    	    var myChart3 = echarts.init(document.getElementById('main3'),'macarons');

			    		var option = {
			    		    tooltip : {
			    		        formatter: "{c}%"
			    		    },
			    		    toolbox: {
			    		        show : false,
			    		        feature : {
			    		            restore : {show: true},
			    		            saveAsImage : {show: true}
			    		        }
			    		    },
			    		    series: [
			    		        {
			    		            name: '',
			    		            type: 'gauge',
			    		            min:0,
			    		            max:100,
			    		            data: [{value: 0, name: ''}],
			    		            axisLine: {            // 坐标轴线
			    		                lineStyle: {       // 属性lineStyle控制线条样式
			    		                    width: 10,
			    		                     color: [[0.2, '#ff4200'], [0.5, '#4584b9'], [1, '#65e725']]
			    		                }
			    		            },
			    		            axisTick: {            // 坐标轴小标记
			    		                length :15,        // 属性length控制线长
			    		                lineStyle: {       // 属性lineStyle控制线条样式
			    		                    color: 'auto'
			    		                }
			    		            },
			    		            detail:{
			    					    show : true,
			    					    width: 100,
			    					    height: 40,
			    					    formatter:'{value}%',
			    					    offsetCenter: [0, '30%'],
			    					    textStyle: {
			    					        fontSize : 20
			    					    }
			    					},
			    					pointer:{
			    					    length : '60%',
			    					    width : 5,
			    					    color : 'auto'
			    					},
			    					startAngle: 190,
			    					endAngle: -10,
			    					// radius: ['95%','95%'],
			    					center: ['50%','70%']
			    		        }
			    		    ]
			    		    
			    		};
			    		var option2 = {
			    		    tooltip : {
			    		        formatter: "{c}%"
			    		    },
			    		    toolbox: {
			    		        show : false,
			    		        feature : {
			    		            restore : {show: true},
			    		            saveAsImage : {show: true}
			    		        }
			    		    },
			    		    series: [
			    		        {
			    		            name: '',
			    		            type: 'gauge',
			    		            min:0,
			    		            max:100,
			    		            data: [{value: 0, name: ''}],
			    		            axisLine: {            // 坐标轴线
			    		                lineStyle: {       // 属性lineStyle控制线条样式
			    		                    width: 10,
			    		                     color: [[0.2, '#65e725'], [0.5, '#4584b9'], [1, '#ff4200']]
			    		                }
			    		            },
			    		            axisTick: {            // 坐标轴小标记
			    		                length :15,        // 属性length控制线长
			    		                lineStyle: {       // 属性lineStyle控制线条样式
			    		                    color: 'auto'
			    		                }
			    		            },
			    		            detail:{
			    					    show : true,
			    					    width: 100,
			    					    height: 40,
			    					    formatter:'{value}%',
			    					    offsetCenter: [0, '30%'],
			    					    textStyle: {
			    					        fontSize : 20
			    					    }
			    					},
			    					pointer:{
			    					    length : '60%',
			    					    width : 5,
			    					    color : 'auto'
			    					},
			    					startAngle: 190,
			    					endAngle: -10,
			    					// radius: ['95%','95%'],
			    					center: ['50%','70%']
			    		        }
			    		    ]
			    		    
			    		};
			    		var option3 = {
			    		    tooltip : {
			    		        formatter: "{c}%"
			    		    },
			    		    toolbox: {
			    		        show : false,
			    		        feature : {
			    		            restore : {show: true},
			    		            saveAsImage : {show: true}
			    		        }
			    		    },
			    		    series: [
			    		        {
			    		            name: '',
			    		            type: 'gauge',
			    		            min:0,
			    		            max:100,
			    		            data: [{value: 0, name: ''}],
			    		            axisLine: {            // 坐标轴线
			    		                lineStyle: {       // 属性lineStyle控制线条样式
			    		                    width: 10,
			    		                     color: [[0.1, '#ff4200'], [0.6, '#e4ba30'], [1, '#65e725']]
			    		                }
			    		            },
			    		            axisTick: {            // 坐标轴小标记
			    		                length :15,        // 属性length控制线长
			    		                lineStyle: {       // 属性lineStyle控制线条样式
			    		                    color: 'auto'
			    		                }
			    		            },
			    		            detail:{
			    					    show : true,
			    					    width: 100,
			    					    height: 40,
			    					    formatter:'{value}%',
			    					    offsetCenter: [0, '30%'],
			    					    textStyle: {
			    					        fontSize : 20
			    					    }
			    					},
			    					pointer:{
			    					    length : '60%',
			    					    width : 5,
			    					    color : 'auto'
			    					},
			    					startAngle: 190,
			    					endAngle: -10,
			    					// radius: ['95%','95%'],
			    					center: ['50%','70%']
			    		        }
			    		    ]
			    		    
			    		};
			    		
			    		
			    		option.series[0].data[0].value = data.data.operatingRate;
			    		myChart.setOption(option, true);
//			    		setInterval(function () {
//			    		},2000);
			    		//--------------------------------------------------------------------------------->>
			    	    option2.series[0].data[0].value = data.data.alarmRate;
			    	    myChart2.setOption(option2, true);
			    	    //--------------------------------------------------------------------------------->>
			    	    option3.series[0].data[0].value = data.data.repairRate;
			    	    myChart3.setOption(option3, true);

			    	    $(window).resize(function() {
			    	    	myChart.resize();
                            myChart2.resize();
                            myChart3.resize();
						})
			    		
			    	}
			    }

			});
			
			
		},
		getTime : function(){
			var today = new Date();  
            var weekday=new Array(7);  
            weekday[0]="星期日";
            weekday[1]="星期一";
            weekday[2]="星期二";
            weekday[3]="星期三";
            weekday[4]="星期四";
            weekday[5]="星期五";
            weekday[6]="星期六";
            
            
            var realTime =today.format('hh:mm:ss');
            var realDate =today.format('yyyy-MM-dd ')+" "+weekday[today.getDay()];
            $(".realTime").html(realTime);
            $(".realDate").html(realDate);
            
		},

		refresh : function () {
            console.log(window.navigator.userAgent.indexOf("MSIE"));
            if (location.href.indexOf("?reload=true") < 0 && window.navigator.userAgent.indexOf("MSIE")>=1) {
                location.href += "?reload=true";
            }
        }
		
	
		
		
		
	};
}();



jQuery(document).ready(function() {
	
	// function refresh() {
	// 	console.log(window.navigator.userAgent.indexOf("MSIE"));
	// 	if (location.href.indexOf("?reload=true") < 0 && window.navigator.userAgent.indexOf("MSIE")>=1) {
	// 		location.href += "?reload=true";
	// 	}
	// }


	setTimeout("IndexTool.refresh()", 1);
	
	IndexTool.setWidth();
	IndexTool.getTime();
	IndexTool.getData();
	
	setInterval(IndexTool.getData(),1000*60);


});